using UnityEngine;

namespace Gj
{
    public class MultipleAnimationHelper : AnimationHelper
    {
        public bool init;
        public bool local = true;
        public bool position;
        public Vector3 positionStart = Vector3.zero;
        public Vector3 positionEnd = Vector3.zero;
        public bool rotation;
        public Vector3 rotationStart = Vector3.zero;
        public Vector3 rotationEnd = Vector3.zero;
        public bool scale;
        public Vector3 scaleStart = Vector3.zero;
        public Vector3 scaleEnd = Vector3.zero;

        protected override void OnUpdate(float value)
        {
            if (position)
            {
                var v = Vector3.Lerp(positionStart, positionEnd, value);
                if (local)
                    Transform.localPosition = v;
                else
                    Transform.position = v;
            }

            if (rotation)
            {
                var v = Vector3.Lerp(rotationStart, rotationEnd, value);
                if (local)
                    Transform.localRotation = Quaternion.Euler(v);
                else
                    Transform.rotation = Quaternion.Euler(v);
            }

            if (scale)
            {
                var v = Vector3.Lerp(scaleStart, scaleEnd, value);
                Transform.localScale = v;
            }
        }

        protected override void OnStart()
        {
            if (init)
            {
                if (position)
                {
                    if (local)
                        Transform.localPosition = forward ? positionStart : positionEnd;
                    else
                        Transform.position = forward ? positionStart : positionEnd;
                }

                if (rotation)
                {
                    if (local)
                        Transform.localRotation = Quaternion.Euler(forward ? rotationStart : rotationEnd);
                    else
                        Transform.rotation = Quaternion.Euler(forward ? rotationStart : rotationEnd);
                }

                if (scale)
                {
                    Transform.localScale = forward ? scaleStart : scaleEnd;
                }
            }
            base.OnStart();
        }
    }
}